package com.hexus.eve.actions.security;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.hexus.eve.entities.security.User;

import com.opensymphony.xwork2.ActionSupport;

public class DeleteUser extends ActionSupport {
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private SessionFactory sessionFactory;
	private String userName;
	
	@Override
	public String execute() throws Exception {
		HibernateTemplate ht = new HibernateTemplate(sessionFactory);
		User user;
		
		//Update or creation of a new item
		if(userName != null) {
			user = ht.get(User.class, userName);
			if(user != null) {
				ht.delete(user);
			}
		}
		return SUCCESS;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		if(userName != null && !"".equals(userName))
			this.userName = userName;
	}
}
